﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.EndItem.CUiEITHideEndItemDescendantsCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.EndItem;

public sealed class CUiEITHideEndItemDescendantsCmd : TxButtonCommand
{
  private CApEITHideEndItemDescendantsEnabler m_enabler;

  public CUiEITHideEndItemDescendantsCmd()
  {
    this.SetStayEnabledInSemiModalMode(true);
    this.m_enabler = new CApEITHideEndItemDescendantsEnabler();
  }

  public virtual string Category => EndItemStringTable.CMD_END_ITEM_CATEGORY;

  public virtual string Name => EndItemStringTable.CMD_END_ITEM_HIDE_NAME;

  public virtual string Tooltip => EndItemStringTable.CMD_END_ITEM_HIDE_TOOLTIP;

  public virtual string Bitmap => "EndItem.HiddenEndItemIcon.bmp";

  public virtual ITxImage Image
  {
    get => (ITxImage) TxImageManager.GetImageByKey("HideEndItemDescendants");
  }

  public virtual string Description => EndItemStringTable.CMD_END_ITEM_HIDE_DESCRIPTION;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  public virtual void Execute(object cmdParams)
  {
    TxObjectList selectedEndItems = CApEITEndItemApp.GetSelectedEndItems();
    TxApplication.ActiveUndoManager.StartTransaction();
    foreach (ITxEndItemProvider itxEndItemProvider in (Collection<ITxObject>) selectedEndItems)
    {
      if (itxEndItemProvider.EndItemRepresentation is ITxEndItemRoot itemRepresentation && itemRepresentation.IsDescendantsExposed)
        itemRepresentation.HideDescendants();
    }
    TxApplication.ActiveUndoManager.EndTransaction();
    TxApplication.ActiveSelection.RemoveItems(selectedEndItems);
    TxApplication.ActiveSelection.AddItems(selectedEndItems);
    TxApplication.RefreshDisplay();
  }
}
